﻿using System;
using System.Collections.Generic;
using Framework;

namespace Enterprise.Admin.Handle
{
    /// <summary>
    /// 获取文章列表JSON
    /// </summary>
    public partial class GetArticleListJson : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var datas = new List<object>();
            var title = Fq("CoTitle").SafeToString();
            var articleCategoryId = Fq("CoArticleCategoryId").SafeToInt();
            var language = Fq("CoLanguage").SafeToString();
            var pageValue = Fq("page").SafeToInt();
            var rowsValue = Fq("rows").SafeToInt();
            var articleService = new ArticleService();
            var table = articleService.GetTable(title, articleCategoryId, language, pageValue, rowsValue,sort,order);
            object result = new { total=table.Total, rows = datas };
            for (int i = 0; i < table.Rows.Count; i++)
            {
                datas.Add(new
                {
                    id = table.Rows[i]["CoArticleId"].SafeToInt(),
                    CoTitle = table.Rows[i]["CoTitle"].SafeToString(),
                    CoArticleCategoryId = table.Rows[i]["CoArticleCategoryId"].SafeToInt(),
                    CoIsRecommend = table.Rows[i]["CoIsRecommend"].SafeToBool(),
                    CoIsPopular = table.Rows[i]["CoIsPopular"].SafeToBool(),
                    CoIsTop = table.Rows[i]["CoIsTop"].SafeToBool(),
                    CoViews = table.Rows[i]["CoViews"].SafeToInt(),
                    CoAuthor = table.Rows[i]["CoAuthor"].SafeToString(),
                    CoDate = table.Rows[i]["CoDate"].SafeToDateTime(),
                    CoIsReserved = table.Rows[i]["CoIsReserved"].SafeToBool(),
                    CoReservedUrl = table.Rows[i]["CoReservedUrl"].SafeToString(),
                    CoCategoryName = table.Rows[i]["CoCategoryName"].SafeToString(),
                    CoLanguage = table.Rows[i]["CoLanguage"].SafeToString(),
                    CoNormalImage = table.Rows[i]["CoNormalImage"].SafeToString(),
                    CoSmallImage = table.Rows[i]["CoSmallImage"].SafeToString(),
                    CoBigImage = table.Rows[i]["CoBigImage"].SafeToString()
                });
            }
            Json(result);
        }
    }
}